package com.xiao.springmvc.controller.company;

import javax.servlet.ServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiao.springmvc.entity.CompanyImage;
import com.xiao.springmvc.entity.CompanyInfo;
import com.xiao.springmvc.service.CompanyImageService;
import com.xiao.springmvc.service.CompanyService;


@Controller
@RequestMapping(value = "/company")
public class CompanyController {

	private static final Logger logger = LoggerFactory.getLogger(CompanyController.class);

	@Autowired
	private CompanyService companyService;
	@Autowired
	private CompanyImageService companyImageService;
	
	@RequestMapping(value="",method=RequestMethod.GET)
	public String list(Model model, ServletRequest request){
		logger.info( "get all company");
		return "company/company";
	}
	
	/**
	 * 获取单个公司信息
	 * @param companyId 
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value="get",method=RequestMethod.GET)
	@ResponseBody
	public Object get(
			@RequestParam("companyId") Long companyId,
			Model model, ServletRequest request){
		Object data = null;
		
		CompanyInfo company = companyService.findOneById(companyId);
		CompanyImage companyImage = companyImageService.findByCompanyId(companyId);
		CompanyJson json = new CompanyJson();
		
		data = json.companyGetJson(company,companyImage);
		
		return data;
	}
	
	/**
	 * 获取公司简介
	 * @param companyId 
	 * @param model
	 * @param request
	 * @return 返回json
	 */
	@RequestMapping(value="introduce",method=RequestMethod.GET)
	@ResponseBody
	public Object introduce(
			@RequestParam("companyId") Long companyId,
			Model model, ServletRequest request){
		Object data = null;
		
		CompanyInfo company = companyService.findOneById(companyId);
		CompanyImage companyImage = companyImageService.findByCompanyId(companyId);
		CompanyJson json = new CompanyJson();
		
		data = json.companyIntroduceJson(company,companyImage);
		
		return data;
	}
	
	
}
